<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
include APPLICATION_PATH."/models/Feedback.php";
include APPLICATION_PATH."/models/News.php";
include APPLICATION_PATH."/models/User.php";
include APPLICATION_PATH."/models/Admin.php";
/**
 * Description of FeedbackController
 *
 * @author Vu
 */
class FeedbackController extends Zend_Controller_Action {
    //put your code here
    public function init() {
        $bootstrap = $this->getInvokeArg("bootstrap");
        $this->aConfig = $bootstrap->getOptions();
        $this->view->aConfig = $this->aConfig;
        $this->modelMapper= new Model_FeedbackMapper();
        $this->model= new Model_Feedback();
        $this->UsermodelMapper= new Model_UserMapper();
        $this->Usermodel= new Model_User();
        $this->AdminmodelMapper= new Model_AdminMapper();
        $this->Adminmodel= new Model_Admin();
        $this->NewsmodelMapper= new Model_NewsMapper();
        $user_login =GlobalLib::getUserLogin();
         $this->user_id = $user_login["id"];
    }
    
    public function indexAction(){
        $this->view->itemnews=$this->NewsmodelMapper->publicpublished5tin(1);
        $this->view->itemfeedback= $this->modelMapper->getFeedback();
    }
    
    public function sendquestionAction(){
        $this->view->itemnews=$this->NewsmodelMapper->publicpublished5tin(1);
        $this->view->my_list_kinhdoanh = $this->AdminmodelMapper->fetchAll_KD_USER($this->user_id);
        if($this->getRequest()->isPost()){
            $redirectUrl = $this->aConfig["site"]["url"] . "default/feedback/index";
            $this->model->setTitle("FEEDBACK");
            if (strlen($_POST["question_kd"]) > 0){
                $this->model->setQuestion(strip_tags($_POST["question_kd"]));
            }
            $this->model->setUser_Id($this->user_id);
            $this->model->setCreated(date("Y/m/d H:i:s"));
            $this->model->setCreated_By($this->user_id);
            $this->model->setModified(date("Y/m/d H:i:s"));
            $this->model->setModified_By(GlobalLib::getLoginId());
            $this->model->setAnswer("");
            $this->model->setAdmin_Id(0);
            $this->modelMapper->save($this->model);
            $this->_redirect($redirectUrl);
        }
    }
    public function listquestionAction(){
        $this->view->itemnews=$this->NewsmodelMapper->publicpublished5tin(1);
        $this->view->itemfeedback= $this->modelMapper->getFeedbackUser($this->user_id);
    }
}
